package com.cskaoyan.mall.product.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cskaoyan.mall.common.result.Result;
import com.cskaoyan.mall.product.dto.SpuBaseSaleAttributeValueDTO;
import com.cskaoyan.mall.product.dto.SpuImageDTO;
import com.cskaoyan.mall.product.dto.SpuInfoPageDTO;
import com.cskaoyan.mall.product.dto.SpuSaleAttributeInfoDTO;
import com.cskaoyan.mall.product.query.SpuInfoParam;
import com.cskaoyan.mall.product.service.SpuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product")
public class AdminSpuController {
    @Autowired
    SpuService spuService;
    @GetMapping("/{page}/{size}")
    public Result getSpu(@PathVariable int page, @PathVariable int size, @RequestParam Long category3Id){
        SpuInfoPageDTO spuInfoPage = spuService.getSpuInfoPage(new Page<>(page, size), category3Id);
        return Result.ok(spuInfoPage);
    }

    @GetMapping("/baseSaleAttrList")
    public Result baseSaleAttrList(){
        List<SpuBaseSaleAttributeValueDTO> spuBaseSaleAttributeValueDTOS = spuService.baseSaleAttrList();
        return Result.ok(spuBaseSaleAttributeValueDTOS);
    }

    @PostMapping("/saveSpuInfo")
    public Result saveSpuInfo(@RequestBody SpuInfoParam spuInfo){
        spuService.saveSpuInfo(spuInfo);
        return Result.ok();
    }

    @GetMapping("/spuImageList/{spuId}")
    public Result spuImageList(@PathVariable Long spuId){
        //通过spuId获取图片列表
        List<SpuImageDTO> spuImageList = spuService.getSpuImageList(spuId);
        return Result.ok(spuImageList);
    }

    @GetMapping("/spuSaleAttrList/{spuId}")
    public Result spuSaleAttrList(@PathVariable Long spuId){
        List<SpuSaleAttributeInfoDTO> spuSaleAttrList = spuService.getSpuSaleAttrList(spuId);
        return Result.ok(spuSaleAttrList);
    }
}
